module ui {

    export class GameSpriteSheet {

        public static readonly info: any = {
            "file": "rthrtb.png", "frames": {
                "num_9": {"x": 55, "y": 0, "w": 51, "h": 62, "offX": 0, "offY": 0, "sourceW": 51, "sourceH": 62},
                "num_8": {"x": 53, "y": 65, "w": 51, "h": 62, "offX": 0, "offY": 0, "sourceW": 51, "sourceH": 62},
                "num_7": {"x": 53, "y": 129, "w": 50, "h": 61, "offX": 0, "offY": 0, "sourceW": 50, "sourceH": 61},
                "num_6": {"x": 0, "y": 129, "w": 51, "h": 62, "offX": 0, "offY": 0, "sourceW": 51, "sourceH": 62},
                "num_5": {"x": 104, "y": 192, "w": 49, "h": 61, "offX": 0, "offY": 0, "sourceW": 49, "sourceH": 61},
                "num_4": {"x": 0, "y": 0, "w": 53, "h": 63, "offX": 0, "offY": 0, "sourceW": 53, "sourceH": 63},
                "num_3": {"x": 53, "y": 192, "w": 49, "h": 62, "offX": 0, "offY": 0, "sourceW": 49, "sourceH": 62},
                "num_2": {"x": 0, "y": 193, "w": 51, "h": 61, "offX": 0, "offY": 0, "sourceW": 51, "sourceH": 61},
                "num_1": {"x": 106, "y": 64, "w": 33, "h": 62, "offX": 0, "offY": 0, "sourceW": 33, "sourceH": 62},
                "num_0": {"x": 0, "y": 65, "w": 51, "h": 62, "offX": 0, "offY": 0, "sourceW": 51, "sourceH": 62}
            }
        };


        private info: any;

        private spriteSheet: egret.SpriteSheet;

        public constructor(img: egret.Texture, info: any = GameSpriteSheet.info) {
            this.info = helper.Helper.clone(info);
            this.spriteSheet = new egret.SpriteSheet(img);
        }

        public getTexture(key: string): egret.Texture {
            let frames: any = this.info["frames"];
            let frame = frames[key];
            if (!frame.isCreated) {
                let texture = this.spriteSheet.createTexture(key, frame.x, frame.y, frame.w, frame.h);
                frame.isCreated = true;
                return texture;
            }
            return this.spriteSheet.getTexture(key);
        }

    }

}